//
//  BZBingFaCell.m
//  QuickCure
//
//  Created by brice Mac on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "BZBingFaCell.h"
#import "BZCureDataModel.h"
#import "BZCureModel.h"

@interface BZBingFaCell()

@property(weak,nonatomic)UIButton *loadBtn;

@end

@implementation BZBingFaCell


+ (NSString *)getReuseId:(id)dict {
    if ([dict isKindOfClass:[BZCureModel class]]) {
        return @"list2";
    }
    else if([dict objectForKey:@"ci3_name"]){
        return @"list1";
    }
    return @"list";
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    UILabel *lb = [[UILabel alloc]init];
    
    _lb_title = lb;
    
    [self.contentView addSubview:lb];
    
    [lb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(30);
    }];
    
    if ([reuseIdentifier isEqualToString:@"list2"]) {
        
        UIButton *btn = [[UIButton alloc]init];
        _btn_choose = btn;
        [self.contentView addSubview:btn];
        [btn setBackgroundColor:[UIColor colorWithRed:0.0 green:0.7288 blue:0.5796 alpha:1.0]];
        
        [btn setTitle:@"订阅" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitle:@"已订阅" forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor colorWithRed:0.875 green:0.2702 blue:0.2056 alpha:1.0] forState:UIControlStateSelected];
        [btn setTitle:@"" forState:UIControlStateDisabled];
        
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(self.contentView).offset(-10);
            make.top.mas_equalTo(self.contentView).offset(5);
            make.bottom.mas_equalTo(self.contentView).offset(-5);
            make.width.mas_equalTo(@70);
        }];
        
    } else if ([reuseIdentifier isEqualToString:@"list1"]) {
        
        
    }
    
    return self;
}

- (void)setModel:(BZCureModel *)model{
    
    _model = model;
    self.btn_choose.selected = model.load;
    _lb_title.text = model.complication_name;
}

- (void)btnClick:(UIButton *)btn {
    
    self.btn_choose.selected = !self.btn_choose.isSelected;
    
    self.model.load = !self.model.load;
    
    if (btn.isSelected) {
        [btn setTitle:self.lb_title.text forState:UIControlStateDisabled];
    }else{
        [btn setTitle:@"" forState:UIControlStateDisabled];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
